/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test.t;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.sql.Connection;

import onpu_dms_xls.API.API;
import onpu_dms_xls.exceptions.MyException;
import onpu_dms_xls.kernel.common.DB.DBConnect;
import onpu_dms_xls.kernel.common.logAndDebug.Debug;

/**
 *
 * @author snbm
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        new Main();
    }

    public Main() {
        Connection con = null;
        try {
            DBConnect dbc = new DBConnect("jdbc:postgresql:onpu", "postgres", "1111");
            con = dbc.getConnection();
        } catch (MyException e) {
            System.out.println(e);
            return;
        }

        File xmlTemplate = new File ("c:\\Temp\\Mytemplates\\C-21_itogova_vidomist.xml");
        File xlsTemplate = new File ("c:\\Temp\\Mytemplates\\C-21_itogova_vidomist.xls");

        try {
            API.getInstance().loadTemplates(
                    con,
                    xlsTemplate,
                    xmlTemplate,
                    Debug.FULL_PRINT,
                    109,
                    1);
        } catch (MyException e) {
            System.out.println(e);
            return;
        } catch (Exception e) {
            System.out.println(e);
            return;
        }


        File inFile = new File("c:\\temp\\111.xls");


        try {
            API.XLS2DB(
                    "<fromDBInputParameters>"
                    + "<constantParameters>"
                        + "<debugMode>FULL_PRINT</debugMode>"
                        + "<documentClassId>109</documentClassId>"
                        + "<temporaryFolder>C:\\temp\\q</temporaryFolder>"
                    + "</constantParameters>"
                    + "</fromDBInputParameters>", con, inFile);
        } catch (MyException e) {
            System.out.println(e);
            return;
        } catch (Exception e) {
            System.out.println(e);
            return;
        }



        File getFileResult = null;

        try {
            getFileResult = API.getInstance().XLSFromDB(
                    "<fromDBInputParameters>"
                    + "<constantParameters>"
                        + "<outputFolder>c:\\temp</outputFolder>"
                        + "<debugMode>FULL_PRINT</debugMode>"
                        + "<output_file_name>файл_відомості_657</output_file_name>"
                        + "<documentClassId>109</documentClassId>"
                        + "<temporaryFolder>c:\\temp\\q</temporaryFolder>"
                    + "</constantParameters>"
                    + "<zeroLevelParameters>"
                        + "<param name=\"detailed_plan_id\">657</param>"
                    + "</zeroLevelParameters> "
                    + "</fromDBInputParameters>", con);
        } catch (MyException e) {
            System.out.println(e);
            return;
        } catch (Exception e) {
            System.out.println(e);
            return;
        }


        System.out.println("Result file absolute path: " + getFileResult.getAbsolutePath());
        System.out.println("Result file name: " + getFileResult.getName());



    }
}
